﻿<Window x:Class="Peter.Interface.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:Commands="clr-namespace:Monti.MVVM.Commands;assembly=Monti"
        xmlns:Docking="clr-namespace:Monti.Docking;assembly=Monti" xmlns:Interface="clr-namespace:Peter.Interface"
        xmlns:Logic="clr-namespace:Peter.Logic"
        Icon="/Peter;component/Images/Editor.ico"
        Title="{Binding Path=WindowTitle}"
        Height="728"
        Width="1024">
   <Commands:CommandBehaviorCollection.Behaviors>
      <Commands:CommandBehavior Event="Loaded"
                                Command="{Binding Path=LoadedCommand}" />
      <Commands:CommandBehavior Event="Closing"
                                Command="{Binding Path=ClosingCommand}" />
   </Commands:CommandBehaviorCollection.Behaviors>

   <Window.DataContext>
      <Logic:MainViewModel />
   </Window.DataContext>
   
   <Window.Resources>      
      <Style x:Key="MenuItemStyle"
             TargetType="{x:Type MenuItem}">
         <Setter Property="Header"
                 Value="{Binding Path=Header}" />
         <Setter Property="ItemsSource"
                 Value="{Binding Path=Children}" />
         <Setter Property="Command"
                 Value="{Binding Path=Command}" />
         <Setter Property="Icon">
            <Setter.Value>
               <Image Source="{Binding Path=IconUrl}" />
            </Setter.Value>
         </Setter>
         <Style.Triggers>
            <DataTrigger Binding="{Binding Path=IconUrl}"
                         Value="{x:Null}">
               <Setter Property="Icon"
                       Value="{x:Null}" />
            </DataTrigger>
            <DataTrigger Binding="{Binding Path=IconUrl}"
                         Value="">
               <Setter Property="Icon"
                       Value="{x:Null}" />
            </DataTrigger>
         </Style.Triggers>
      </Style>

      <DataTemplate x:Key="ToolbarButtonTemplate">
         <DataTemplate.Resources>
            <Style TargetType="Button">
               <Setter Property="Background"
                       Value="Transparent" />
               <Setter Property="Template">
                  <Setter.Value>
                     <ControlTemplate TargetType="Button">
                        <Border BorderThickness="1"
                                BorderBrush="Transparent"
                                x:Name="PART_Border"
                                Background="{TemplateBinding Background}">
                           <ContentPresenter Content="{TemplateBinding Content}"
                                             Margin="5" />
                        </Border>
                        <ControlTemplate.Triggers>
                           <Trigger Property="IsMouseOver"
                                    Value="True">
                              <Setter Property="BorderBrush"
                                      TargetName="PART_Border"
                                      Value="#E5C365" />
                              <Setter Property="Background"
                                      TargetName="PART_Border">
                                 <Setter.Value>
                                    <LinearGradientBrush StartPoint="0,0"
                                                         EndPoint="0,1">
                                       <GradientStop Color="#FFE8A6"
                                                     Offset=".4" />
                                       <GradientStop Color="#FFEDBA"
                                                     Offset=".6" />
                                       <GradientStop Color="#FFFAEC" />
                                    </LinearGradientBrush>
                                 </Setter.Value>
                              </Setter>
                           </Trigger>
                           <Trigger Property="IsPressed"
                                    Value="True">
                              <Setter Property="BorderBrush"
                                      TargetName="PART_Border"
                                      Value="#E5C365" />
                              <Setter Property="Background"
                                      TargetName="PART_Border">
                                 <Setter.Value>
                                    <LinearGradientBrush StartPoint="0,0"
                                                         EndPoint="0,1">
                                       <GradientStop Color="#E5C365"
                                                     Offset=".4" />
                                       <GradientStop Color="#FFE8A6"
                                                     Offset=".6" />
                                       <GradientStop Color="#FFEDBA" />
                                    </LinearGradientBrush>
                                 </Setter.Value>
                              </Setter>
                           </Trigger>
                        </ControlTemplate.Triggers>
                     </ControlTemplate>
                  </Setter.Value>
               </Setter>
            </Style>
         </DataTemplate.Resources>
         <Button Command="{Binding Path=DataContext.Command, RelativeSource={RelativeSource AncestorType=ContentControl}}"
                 ToolTip="{Binding Path=DataContext.Text, RelativeSource={RelativeSource AncestorType=ContentControl}}">
            <Image Source="{Binding Path=DataContext.IconUrl, RelativeSource={RelativeSource AncestorType=ContentControl, AncestorLevel=2}}"
                   Width="16" Height="16"/>
         </Button>
      </DataTemplate>
      
      <DataTemplate x:Key="ToolbarItemTemplate">
         <ContentControl ContentTemplate="{StaticResource ToolbarButtonTemplate}">
            <ContentPresenter />
         </ContentControl>
      </DataTemplate>
      
      <DataTemplate x:Key="EditorHeaderTemplate"
                    DataType="{x:Type Logic:EditorViewModel}">
         <TextBlock Text="{Binding Path=Content.FileName}"
                    ToolTip="{Binding Path=Content.FilePath}" />
      </DataTemplate>

      <DataTemplate x:Key="FileExplorerHeaderTemplate"
                    DataType="{x:Type Logic:FileExplorerViewModel}">
         <TextBlock Text="{Binding Path=Content.Title}" />
      </DataTemplate>

      <DataTemplate x:Key="EditorTemplate"
                    DataType="{x:Type Logic:EditorViewModel}">
         <ContentControl Content="{Binding Path=Content}" />
      </DataTemplate>
      
      <DataTemplate x:Key="ImageViewerTemplate"
                    DataType="{x:Type Logic:ImageViewModel}">
         <Interface:ImageView />
      </DataTemplate>

      <DataTemplate x:Key="FileExplorerTemplate"
                    DataType="{x:Type Logic:FileExplorerViewModel}">
         <Interface:FileExplorerView />
      </DataTemplate>
   </Window.Resources>
   
   <Grid>
      <Grid.RowDefinitions>
         <RowDefinition Height="Auto" />
         <RowDefinition Height="Auto" />
         <RowDefinition Height="*" />
      </Grid.RowDefinitions>
      
      <Menu ItemsSource="{Binding Path=MenuItems}"
            ItemContainerStyle="{StaticResource MenuItemStyle}" />

      <ItemsControl Grid.Row="1"
                    Width="Auto"
                    Height="Auto"
                    Background="#CED4DF"
                    ItemsSource="{Binding Path=ToolbarItems}"
                    ItemTemplate="{StaticResource ToolbarItemTemplate}">
         <ItemsControl.ItemsPanel>
            <ItemsPanelTemplate>
               <WrapPanel Orientation="Horizontal" />
            </ItemsPanelTemplate>
         </ItemsControl.ItemsPanel>
      </ItemsControl>
      
      <Docking:DockManager Grid.Row="3"
                           ActiveContent="{Binding Path=ActiveContent, Mode=TwoWay}"
                           Documents="{Binding Path=Documents, Mode=TwoWay}"
                           LeftToolWindows="{Binding Path=LeftToolWindows, Mode=TwoWay}"
                           TemplateSelector="{Binding Path=DockingTemplateSelector, Mode=TwoWay}" />
   </Grid>
</Window>
